package com.axend.aerosense.home.adapter;

import android.content.Context;
import android.view.View;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseDataBindingHolder;
import com.axend.aerosense.common.bean.AlarmBean;
import com.axend.aerosense.common.bean.LogType;
import com.axend.aerosense.common.util.DateUtil;
import com.axend.aerosense.home.R;
import com.axend.aerosense.home.databinding.HomeFragmentAlarmItemBinding;
import org.jetbrains.annotations.NotNull;


public class HomeFragmentAlarmAdapter extends BaseQuickAdapter<AlarmBean, BaseDataBindingHolder<HomeFragmentAlarmItemBinding>> {
    private LogType warningTYPE;

    public HomeFragmentAlarmAdapter() {
        super(R.layout.home_fragment_alarm_item);
    }

    @Override
    protected void convert(@NotNull BaseDataBindingHolder<HomeFragmentAlarmItemBinding> baseViewHolder, AlarmBean alarmBean) {

        HomeFragmentAlarmItemBinding viewDataBinding = baseViewHolder.getDataBinding();
        if (null == alarmBean || null == viewDataBinding) {
            return;
        }
        viewDataBinding.userAlarmHomeT.setText(alarmBean.getRoomName());
        String title = alarmBean.getEventTypeName(); // + baseViewHolder.itemView.getContext().getString(R.string.common_alarm);
        viewDataBinding.userAlarmInfo.setText(title);
        viewDataBinding.userAlarmTime.setText(DateUtil.getStringDateJudgeToday(alarmBean.getAlarmTime()));

        Context context = viewDataBinding.getRoot().getContext();
        if(alarmBean.getAlertLogState() == 0){
            //未读
            viewDataBinding.homeItemConstraintLayout.setBackground(context.getDrawable(R.drawable.home_alarm_list_unred_item_selector));
            viewDataBinding.userAlarmImageview.setVisibility(View.VISIBLE);
            viewDataBinding.userAlarmInfo.setTextColor(context.getColor(R.color.common_alert_text_red));
            viewDataBinding.userAlarmHomeT.setTextColor(context.getColor(R.color.common_text_color_black));
            viewDataBinding.userAlarmTime.setTextColor(context.getColor(R.color.common_text_color_black));
        }else{
            //已读
            viewDataBinding.userAlarmImageview.setVisibility(View.INVISIBLE);
            viewDataBinding.homeItemConstraintLayout.setBackground(context.getDrawable(R.drawable.home_alarm_list_red_item_selector));
            viewDataBinding.userAlarmInfo.setTextColor(context.getColor(R.color.common_text_color_gray));
            viewDataBinding.userAlarmHomeT.setTextColor(context.getColor(R.color.common_text_color_gray));
            viewDataBinding.userAlarmTime.setTextColor(context.getColor(R.color.common_text_color_gray));
        }

        //报警图片类型
        if(LogType.FALL_DOWN.getType() == alarmBean.getAlertTypeId()){
//            if(alarmBean.getAlertLogState() == 0){
//                viewDataBinding.userAlarmImageview.setImageResource(R.drawable.common_user_icon_fall2);
//            }else{
//                viewDataBinding.userAlarmImageview.setImageResource(R.drawable.common_user_icon_fall1);
//            }
            viewDataBinding.userAlarmImageview.setImageResource(R.drawable.common_user_icon_fall);


        }else if(LogType.SLEEP_TIMEOUT.getType() == alarmBean.getAlertTypeId()){
//            if(alarmBean.getAlertLogState() == 0){
//                viewDataBinding.userAlarmImageview.setImageResource(R.drawable.common_sleeptimeout2);
//            }else{
//                viewDataBinding.userAlarmImageview.setImageResource(R.drawable.common_sleeptimeout1);
//            }
            viewDataBinding.userAlarmImageview.setImageResource(R.drawable.common_sleeptimeout);


        }else if(LogType.INTRUDE.getType() == alarmBean.getAlertTypeId()){
//            if(alarmBean.getAlertLogState() == 0){
//                viewDataBinding.userAlarmImageview.setImageResource(R.drawable.common_intrusion2);
//            }else{
//                viewDataBinding.userAlarmImageview.setImageResource(R.drawable.common_intrusion1);
//            }
            viewDataBinding.userAlarmImageview.setImageResource(R.drawable.common_intrusion);


        }else if(LogType.GO_OUT_NOT_BACK.getType() == alarmBean.getAlertTypeId()){
//            if(alarmBean.getAlertLogState() == 0){
//                viewDataBinding.userAlarmImageview.setImageResource(R.drawable.common_outdoor2);
//            }else{
//                viewDataBinding.userAlarmImageview.setImageResource(R.drawable.common_outdoor1);
//            }
            viewDataBinding.userAlarmImageview.setImageResource(R.drawable.common_outdoor);


        }else if(LogType.ToiletDetention.getType() == alarmBean.getAlertTypeId()){
//            if(alarmBean.getAlertLogState() == 0){
//                viewDataBinding.userAlarmImageview.setImageResource(R.drawable.common_bathroom2);
//            }else{
//                viewDataBinding.userAlarmImageview.setImageResource(R.drawable.common_bathroom1);
//            }
            viewDataBinding.userAlarmImageview.setImageResource(R.drawable.common_bathroom);



        }else if(LogType.NightNotBack.getType() == alarmBean.getAlertTypeId()){
//            if(alarmBean.getAlertLogState() == 0){
//                viewDataBinding.userAlarmImageview.setImageResource(R.drawable.common_getoutroom2);
//            }else{
//                viewDataBinding.userAlarmImageview.setImageResource(R.drawable.common_getoutroom1);
//            }
            viewDataBinding.userAlarmImageview.setImageResource(R.drawable.common_getoutroom);

        }else if(LogType.DEVICE_OFFLINE.getType() == alarmBean.getAlertTypeId()){
            if(alarmBean.getAlertLogState() == 0){
                viewDataBinding.userAlarmImageview.setImageResource(R.drawable.common_user_icon_off_line2);
            }else{
                viewDataBinding.userAlarmImageview.setImageResource(R.drawable.common_user_icon_off_line2);
            }

        }else if (LogType.StandingStill.getType() == alarmBean.getAlertTypeId()){
            viewDataBinding.userAlarmImageview.setImageResource(R.drawable.common_icon_motionless_alert);

        }else if (LogType.NoVitalSignals.getType() == alarmBean.getAlertTypeId()){
            viewDataBinding.userAlarmImageview.setImageResource(R.drawable.common_icon_no_vital_signals);

        }else if (LogType.BedExitWarning.getType() == alarmBean.getAlertTypeId()){
            viewDataBinding.userAlarmImageview.setImageResource(R.drawable.common_icon_bed_exit_warning);

        }else if (LogType.AbnormalSleep.getType() == alarmBean.getAlertTypeId()){
            viewDataBinding.userAlarmImageview.setImageResource(R.drawable.common_icon_abnormal_sleep);

        }
    }

}
